<script setup lang="ts">
import { onMounted, ref } from 'vue';
import HelloWorld from './components/HelloWorld.vue'

/* 
4. 泛型工具类型
ReturnType<typeof 函数>: 得到函数返回值类型
InstanceType<typeof 组件>：得到组件对象的类型 
*/

const a = (value: string) => {
  return value.toUpperCase()
}
console.log(typeof a) // 'function'   使用的是JS的typeof  得到类型名称
const b: typeof a = (x: string) => {  // 是TS的typeof   得到类型
  return x + 'abc'
}
console.log(b)
const c: ReturnType<typeof a> = 'abcc'
console.log(c)
type Xxx = ReturnType<typeof a>
let d: Xxx = 'aaa'
console.log(d)

const hw = ref<InstanceType<typeof HelloWorld>>()

onMounted(() => {
  hw.value?.fn()   
  /* 
    if (hw.value) {
      hw.value.fn()   
    }
  */
})

</script>

<template>
  <div>
    <a href="https://vitejs.dev" target="_blank">
      <img src="/vite.svg" class="logo" alt="Vite logo" />
    </a>
    <a href="https://vuejs.org/" target="_blank">
      <img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
    </a>
  </div>
  <HelloWorld ref="hw" msg="Vite + Vue" />
</template>

<style scoped>
.logo {
  height: 6em;
  padding: 1.5em;
  will-change: filter;
  transition: filter 300ms;
}
.logo:hover {
  filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
  filter: drop-shadow(0 0 2em #42b883aa);
}
</style>
